package model

import (
	"gitee.com/xuxinzhi2206/corehub/database/mysql"
	"gorm.io/gorm"
)

// 邀请好友表
type Invite struct {
	gorm.Model
	InviterId int64 `gorm:"type:int(11);not null;comment:邀请人"`
	InviteeId int64 `gorm:"type:int(11);not null;comment:受邀者"`
	Count     int64 `gorm:"column:count;type:int(11);"`
}

func (u *Invite) CreateInvite() (*Invite, error) {
	return u, mysql.WithMysql(func(db *gorm.DB) error {
		return db.Create(u).Error
	})
}

func (u *Invite) GetInviteInfo() (res Invite, err error) {
	return res, mysql.WithMysql(func(db *gorm.DB) error {
		return db.Where("inviter_id =? AND invitee_id =?", u.InviterId, u.InviteeId).First(&res).Error
	})

}
func (u *Invite) GetInvite() (info []*Invite, err error) {
	return info, mysql.WithMysql(func(db *gorm.DB) error {
		return db.Where("inviter_id = ?", u.InviterId).Find(&info).Error
	})
}
